﻿#ifndef PST_TABLESETTINGS_H
#define PST_TABLESETTINGS_H

#include <QWidget>
#include <QStandardItemModel>
#include "ui_TableSettings.h"
#include "TableDisplayWindow.h"
#include "TableFilterSelectDataBar.h"

namespace pst 
{
    class TableSettings : public QWidget
    {
        Q_OBJECT
    
    public:
        void addData(TableDisplayWindow* tableDisplayWindow);
        void setDataSource(QString dataSourceText);
        void addDataFilterVarItem(TableDisplayWindow* tableDisplayWindow);
        void setTableChartDataInfo(InfomationGraph3DBasical* info) { m_info = info; };
        void updataTableChartDataByOpenProject();

        void clearData();

        // python
        void pyHideOrShowTableColumn(QSet<int>& columnIndexs);
        void pyChangColName(const int index, QString newName);
        void pyFlushTableBySelectedRow(const QHash<int, QStringList> map);
        void pySetSelectedIndex(QSet<int> indexs);

    public:
        TableSettings(QWidget* parent = nullptr);
        ~TableSettings();

    private:
        Ui::TableSettings *ui;
        QIcon m_eyeHiden;
        QIcon m_eyeShow;
        QStandardItemModel *m_dataStandardItemModel;
        QHash<int, QStringList> m_indexMap;
        QHash<int, QString> m_indexNameMap;
        QHash<int, TableFilterSelectDataBar*> m_barMap;
        InfomationGraph3DBasical* m_info;
        QList<TableFilterSelectDataBar*> m_filterSelectDataBars;

    signals:
        void signal_showOrHideColumn(QSet<int>& columnIndexs, bool savePy = true);
        void signal_changeColumnName(QHash<int, QString>& hash, bool& execRes);
        void signal_flushTableBySelectedRow(QHash<int, QStringList>& map, bool savePy);
        void signal_highlightSelectedTableColumns(QSet<int>& columnIndexs);

        void signal_importFlushTableBySelectedRow(QHash<int, QStringList>& map, bool savePy);
        void signal_importShowOrHideColumn(QSet<int>& columnIndexs, bool savePy = false);
        void signal_importChangeColumnName(QHash<int, QString>& hash);
        

    private slots:
        void slot_showContextMenu(const QPoint& pos);
        void slot_changColName(const QModelIndex& index);
        void slot_highlightSelectedTableColumns(const QModelIndex& index);
        void slot_showOrHideColumn(const QModelIndex& index);
        void slot_flushTableBySelectedRow(QHash<int, QStringList>* map, bool savePy);
    };

} // namespace pst
#endif // !PST_TABLESETTINGS_H
